from django.db import models
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from rest_framework.generics import ListAPIView


# Create your models here.
#存储公共的模型属性

class BaseModel(models.Model):
    name=models.CharField(max_length=50,verbose_name='名称')
    create_time = models.DateTimeField(auto_now_add=True,verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True,verbose_name='更新时间')
    is_delete = models.BooleanField(default=False,verbose_name='删除标记')
    is_show = models.BooleanField(default=True,verbose_name='是否显示')
    orders = models.IntegerField(default=0,verbose_name='排序')
    class Meta:
        abstract = True #抽象模型，不会在数据库生成表
    def __str__(self):
        return self.name

class CacheView(ListAPIView):
    @method_decorator(cache_page(60*60*24))
    def get(self, request, *args, **kwargs):
        return super().get(request, *args, **kwargs)
